#include <stdio.h>
/* linked list is suit this handle */
void insert_sort(int *arrary, int item_num)
{
    int  i = 0;
    int j = 0;
    int temp_value = 0;
    
    for (i = 1; i < item_num; i++) {
        if (arrary[i] < arrary[i - 1]) {
            temp_value = arrary[i];
            
            for (j = i-1; j>=0 && temp_value < arrary[j]; j--) {
               arrary[j+1] = arrary[j];
            }
            arrary[j+1] = temp_value; // for loop finish j reduce one more
        }
    }
    
    printf("insert sort result: ");
    for (i = 0; i < item_num; i++) {
        printf("%d\t", arrary[i]);
    }
    printf("\n");
    return;
}

int main()
{
    int arrary[10] = {5, 4, 3, 2, 1, 9, 8, 7, 6, 10};
    int arrary2[10] = {5, 2, 3, 2, 1, 10, 8, 7, 6, 10};
    int item_num = sizeof(arrary)/sizeof(int);
    
    printf("=============================================\n");
    insert_sort(arrary, item_num);
    printf("=============================================\n");
    insert_sort(arrary2, item_num);
    
    return 0;
}